<?php
class DepartmentController extends DefaultController{
	public function _default(){
		$departmentList = $this->_departmentList();
		$this->assign('departmentList', $departmentList);
		$this->display();
	}
	
	public function show(){
		$id = request('id');
		
		if (!$id){
			$this->_404();
		}
		
		$ip = get_client_ip();
		
		$ipInfo = IpBusiness::calcIp($ip);
		$this->assign('myDepartment', $ipInfo['department_id']==$id);
		
		$department = DepartmentModel::get($id);
		$this->assign('department', $department);
		$this->display();
	}
	
	public function recommend(){
		$ip = get_client_ip();
		
		$ipInfo = IpBusiness::calcIp($ip);
		
		$deparment = array();
		if (isset($ipInfo['department_id']) && $ipInfo['department_id']){
			$deparment = DepartmentModel::get($ipInfo['department_id']);
		}
		$this->assign('department', $deparment);
		if ($deparment){
			$this->assign('myDepartment', true);
			$this->display('department_show');
		}else{
			$this->display();
		}
	}
}